<template>
    <h3>这里是人员负载查看</h3>
    <el-divider />
    <el-button type="primary" @click="getMemberList">获取用户</el-button>
    <el-divider />
    用户列表:
    <br><br>
    <el-row>
        <el-button v-for="member in currentMemberList" type="primary" :key="member.Id" @click="getMemberProjectList(member)"
            plain>{{ member.Name }}</el-button>
    </el-row>

    <el-divider />
    {{ currentMenber.Name }}项目列表:
    <br><br>
    <el-row>
        <el-button v-for="project in currentProjectList" type="success" :key="project.Id"
            @click="getMemberProjectIssueList(currentMenber, project)" plain>{{
                project.DisplayName
            }}</el-button>
    </el-row>

    <el-divider />
    {{ currentMenber.Name }}-{{ currentProject.DisplayName }}任务项:
    <br><br>
    <el-row v-for="issue in currentIssueList">
        <el-button :type="getButtonTypeByPriority(issue.Priority)" :key="issue.Id" plain>{{
            issue.Name
        }}</el-button>

    </el-row>
</template>

<script setup lang="ts">

import { reactive, ref } from "vue";
import * as codingOpenApi from "../../api/CodingOpenApi";

const currentMemberList: Array<any> = reactive<Array<any>>(new Array<any>);
const currentProjectList: Array<any> = reactive<Array<any>>(new Array<any>);
const currentIssueList: Array<any> = reactive<Array<any>>(new Array<any>);
const currentMenber: any = reactive<any>({
    Name: "",
    Id: ''
});
const currentProject: any = reactive<any>({
    DisplayName: "",
    Id: ''
});

/**
 * 获取成员列表
 */
const getMemberList = () => {
    currentIssueList.length = 0;
    currentProject.DisplayName = '';
    codingOpenApi.getUserList().then(response => {
        let teamMembers = response.data.Response?.Data?.TeamMembers;
        if (teamMembers) {
            currentMemberList.length = 0;
            currentMemberList.push(...teamMembers);
        }
    })
};

/**
 * 根据成员获取任务id
 */
const getMemberProjectList = (member: any) => {
    currentMenber.Name = member.Name;
    currentMenber.Id = member.Id;
    codingOpenApi.getUserProjectList(member.Id).then(response => {
        let projectList = response.data.Response?.ProjectList;
        if (projectList) {
            currentProjectList.length = 0;
            currentProjectList.push(...projectList);
        }
    })
};

/**
 * 获取成员项目对应的事项
 */
const getMemberProjectIssueList = (member: any, project: any) => {
    currentProject.Name = project.Name;
    currentProject.Id = project.Id;
    codingOpenApi.getUserProjectIssueList("" + member.Id, project.Name).then(response => {
        let issueList = response.data.Response?.Data?.List;
        if (issueList) {
            currentIssueList.length = 0;
            currentIssueList.push(...issueList);
        }
    })
};


const getButtonTypeByPriority = (priority: string) => {

    if (priority == "0") {
        return "success"
    }
    if (priority == "1") {
        return ""
    }
    if (priority == "2") {
        return "warning"
    }
    if (priority == "3") {
        return "danger"
    }
}

</script>

<style>
.el-row>.el-button {
    margin-bottom: 10px;
}
</style>